package com.atguigu.rabbit.producer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitmqTopicExchangeConfiguration {

    // 声明交换机
    @Bean
    public Exchange topicExchange() {
        Exchange topicExchange = ExchangeBuilder.topicExchange("topic_exchange").durable(true).build();
        return topicExchange ;
    }

    // 声明队列
    @Bean
    public Queue topicQueue01() {
        Queue queue = QueueBuilder.durable("topic_queue_01").build();
        return queue ;
    }

    // 声明队列
    @Bean
    public Queue topicQueue02() {
        Queue queue = QueueBuilder.durable("topic_queue_02").build();
        return queue ;
    }

    // 声明队列和交换机的绑定信息
    @Bean
    public Binding topicQueue01Binding() {
        Binding binding = BindingBuilder.bind(topicQueue01()).to(topicExchange())
                .with("*.baidu.*").noargs();
        return binding ;
    }

    @Bean
    public Binding topicQueue02BindingErrorRoutingKey() {
        Binding binding = BindingBuilder.bind(topicQueue02()).to(topicExchange())
                .with("*.*.com").noargs() ;
        return binding ;
    }

    @Bean
    public Binding topicQueue02BindingInfoRoutingKey() {
        Binding binding = BindingBuilder.bind(topicQueue02()).to(topicExchange())
                .with("www.#").noargs() ;
        return binding ;
    }


}